<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Mod_department extends PNC_Model {

    /*public function show_department($per_page, $offset) {
        $query_dept = $this
                ->db
                ->select('*')
                ->from('pnc_employee')
                ->join('pnc_department', 'pnc_department.dept_id = pnc_employee.dept_id')
                ->join('pnc_position', 'pnc_position.pos_id = pnc_employee.pos_id')
                ->where('pnc_position.pos_id', 2)
                ->or_where('pnc_position.pos_id', 1)
               // ->limit($per_page, $offset)
                ->get();
        if ($query_dept->num_rows() > 0) {
            foreach ($query_dept->result() as $dept) {
                $data[] = $dept;
            }
            return $data;
        }
        return FALSE;
    }
*/
   /* function show_subdepartment($per_page, $offset) {
        $query_dept = $this
                ->db
                ->select("*")
                ->from("pnc_employee")
                ->join("pnc_department", "pnc_department.dept_id = pnc_employee.sub_dept")
                ->join("pnc_position", "pnc_position.pos_id = pnc_employee.pos_id")
//				->where("pnc_department.dept_id", 7)
//				->or_where("pnc_department.dept_id", 8)
                ->where('pnc_department.sub_dept', 1)
                ->limit($per_page, $offset)
                ->get();
        if ($query_dept->num_rows() > 0) {
            foreach ($query_dept->result() as $dept) {
                $data[] = $dept;
            }
            return $data;
        }
        return FALSE;
    }*/

   /* public function get_department($dept_alias){
        $query_dept = $this
                ->db
                ->select('dept_id')
                ->from('pnc_department')
                ->where('dept_alias', $dept_alias)
                ->get();
        if ($query_dept->num_rows() > 0) {
            foreach ($query_dept->result_array() as $dept) {
                $data = $dept['dept_id'];
            }
            return $data;
        }
    }*/

    /*
     * Delete department with id
     * @access public
     * @param int
     */
	 /*
public function delete_individual($id) {
		$this->db->where('pos_id', $id);
		return $this->db->delete('pnc_position');
	}*/
   public function deleted($id) {
        $this->db->where('pos_id', $id);
        return $this->db->delete('pnc_position');
    }

    public function add_position($name) {
        $data = array(
            'pos_name' => $name,
        );
        $this->db->insert('pnc_position', $data);
        return $this->db->affected_rows() > 0;
    }
	
	public function get_position($pos_id) {
		$query = $this->db
				->select('*')
				->from('pnc_position')
				->where('pos_id', $pos_id)
				->get();
		return $query;
	}
	/* Update position */
	public function update_position($id, $get_pos_name) {
		$data = array('pos_name' => $get_pos_name);	
		$this->db->where('pos_id', $id);
		return $this->db->update('pnc_position', $data);
	}
	
	public function count_position() {
		return $this->db->count_all("pnc_position");
	}
	function m_position($per_page,$offset){
		 $query_dept = $this
                ->db
                ->select('*')
                ->from('pnc_position')
				->order_by('pos_name', 'ASC')
                ->limit($per_page,$offset)
                ->get();
        if ($query_dept->num_rows() > 0) {
            foreach ($query_dept->result() as $dept) {
                $data[] = $dept;
            }
            return $data;
        }
        return FALSE;
    
		
		
		}

}
